package com.srv;

import java.util.HashMap;

/**
 * HTTP Content Type
 * @author Administrator
 *
 */
public class ContentType {
	public final static int IMAGE_PNG=10;
	public final static int IMAGE_GIF=11;
	public final static int IMAGE_JPEG=12;
	
	public final static int AUDIO_MPEG=20;
	public final static int AUDIO_AMR=21;
	
	
	public final static int APPLICATION_OCTET_STREAM=30;
	
	public final static int UNKOWN=90;
	
	private static HashMap<Integer,String> hm = new HashMap();
	static{		
		hm.put(Integer.valueOf(ContentType.IMAGE_PNG), "image/png");
		hm.put(Integer.valueOf(ContentType.IMAGE_GIF), "image/gif");
		hm.put(Integer.valueOf(ContentType.IMAGE_JPEG), "image/jpeg");		
		hm.put(Integer.valueOf(ContentType.AUDIO_MPEG), "audio/mpeg");
		hm.put(Integer.valueOf(ContentType.AUDIO_AMR), "audio/amr");		
		
		hm.put(Integer.valueOf(ContentType.APPLICATION_OCTET_STREAM), "application/octet-stream");
	}
	private static HashMap<String,Integer> hm2 = new HashMap();
	static{		
		hm2.put("image/png",Integer.valueOf(ContentType.IMAGE_PNG));
		hm2.put("image/gif",Integer.valueOf(ContentType.IMAGE_GIF));
		hm2.put("image/jpeg",Integer.valueOf(ContentType.IMAGE_JPEG));		
		hm2.put("audio/mpeg",Integer.valueOf(ContentType.AUDIO_MPEG));
		hm2.put("audio/amr",Integer.valueOf(ContentType.AUDIO_AMR));
		hm2.put("application/octet-stream",Integer.valueOf(ContentType.APPLICATION_OCTET_STREAM));
	}
	public static String getString(int contentType){
		return ContentType.hm.get(Integer.valueOf(contentType));
	}
	public static int getInt(String contentType){
		if(contentType==null){return UNKOWN;}
		Integer i = ContentType.hm2.get(contentType.toLowerCase());
		if(i==null){return UNKOWN;}
		return i.intValue();
	}
	public static int getIntByFileName(String fileName){
		if(fileName==null){return ContentType.UNKOWN;}		
		String t = fileName.toLowerCase();
		if(t.endsWith(".gif")){return ContentType.IMAGE_GIF;}
		if(t.endsWith(".jpg")){return ContentType.IMAGE_JPEG;}
		if(t.endsWith(".jpeg")){return ContentType.IMAGE_JPEG;}
		if(t.endsWith(".png")){return ContentType.IMAGE_PNG;}
		if(t.endsWith(".amr")){return ContentType.AUDIO_AMR;}
		return ContentType.UNKOWN;
	}
	
	

}
